package com.apache.log.es.config;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

public class EsMap extends HashMap<String, Object> {

	public Object put(String key, Object value) {
		if(value instanceof Double){
			double vl = (Double)value;
			long dds = Double.valueOf(vl).longValue();
			if(dds == 0)
				return "";
//			String val = longToStr(dds,"yyyy-MM-dd HH:mm:ss");
//			if(!"createDate".equalsIgnoreCase(key) && !"updateDate".equalsIgnoreCase(key)){
//				super.put(key.replace("Date","")+"Long", dds);
//			}
			return super.put(key, dds);
		} else {
			return super.put(key, value);
		}
	}

	public void putAll(java.util.Map<? extends String, ? extends Object> map) {
		super.putAll(map);
	}

	// not @Override because that would require the key parameter to be of type Object
	public Object get(String key) {
		return super.get(key);
	}

	public String getStr(String key){
		return String.valueOf(super.get(key));
	}

	/**
	 * 将毫秒数值日期转化为字符串日期
	 *
	 * @param time    毫秒数
	 * @param fmtStr  日期格式类
	 * @return String 将参数time转换成格式为fmtStr的字符串日期
	 */
	private String longToStr(long time, String fmtStr) {
		Date date = Calendar.getInstance().getTime();
		date.setTime(time);
		return new SimpleDateFormat(fmtStr).format(date);
	}
}
